<?php
namespace froyo\cherry\Base;


class BaseController extends BaseObject{
	protected $request;
	protected $module;
	protected $app;
	protected $view;
	protected $viewdir = 'views';


	//获取view
	public function getView(){
		if(!$this->view)
		{
			$this->view = new BaseView();
		}
		return $this->view;
	}

	public function render($viewname,$params=[]){
		$viewnamearray = explode('/', $viewname);
		$path = $this->module->getClassDirPath().'/'.$this->viewdir;

		if(count($viewnamearray) ==1)
		{
			//获取控制器名称
			$dir = lcfirst($this->getClassName());
			$path .= '/'.$dir;
			$path .= '/'.$viewnamearray[0];
		}
		else
		{
			 $path .= '/'.$viewname;
		}
		$path = $path.'.php';
		return $this->getView()->render($path,$params);
	}

}